# -*- coding: utf-8 -*-
# @Time : 2021/9/9 18:34
# @Author : 伟哥
# @Email : xw@gmail.com
# @File : CRM-ST-XSJH-002.py
# @Project : crm
'''验证添加商机功能，商机名输入2位'''


from time import sleep
from selenium.webdriver.common.by import By
from selenium import webdriver
from utils.get_cookie import cookie
from utils import util

#定位器
fzr_locator=(By.CSS_SELECTOR,"#owner_name")
fzr_xz_locator=(By.XPATH,"//*[@id='d_content']/tr[1]/td[1]/input")
fzr_queren_locator=(By.XPATH,'/html/body/div[12]/div[3]/div/button[1]/span')
kehu_locator=(By.CSS_SELECTOR,'#customer_name')
kehu_xz_locator=(By.XPATH,'//*[@id="datas"]/tr[1]/td[1]/input')
kehu_queren_locator=(By.XPATH,"/html/body/div[10]/div[3]/div/button[1]/span")
shangji_name_locator=(By.CSS_SELECTOR,'#name')
yuqijiage_locator=(By.CSS_SELECTOR,'#estimate_price')
baicheng_locator=(By.CSS_SELECTOR,'input[value="保存"')
#前提条件
cookie=cookie(util.HOST,util.name,util.password)
driver=webdriver.Chrome()
driver.add_cookie(cookie)
driver.get('http://192.168.1.155/crm/index.php?m=business&a=add')

#测试用例步骤

try:
    #选择负责人
    driver.find_element(*fzr_locator).click()
    driver.find_element(*fzr_xz_locator).click()
    driver.find_element(*fzr_queren_locator).click()


    #选择客户
    driver.find_element(*kehu_locator).click()
    driver.find_element(*kehu_xz_locator).click()
    driver.find_element(*kehu_queren_locator).click()

    #输入商机名
    driver.find_element(*shangji_name_locator).send_keys("软件")

    #输入预期价格
    driver.find_element(*yuqijiage_locator).send_keys("1212")

    #点击保存
    driver.find_element(*baicheng_locator).click()

except Exception as e:
    raise e
finally:
    sleep(5)
    driver.quit()